#!/usr/bin/python
#-*- coding: utf-8 -*-

import sys, cv2
import pprint as pp

points = []

def on_mouse(event, x, y, flags, param):

    #Bild im Fenster anzeigen
    cv2.imshow("Image Viewer",image)
    
    if event == cv2.EVENT_LBUTTONDOWN:
        
        length = len(points)
        point=(x,y)

        print 'len', length, points
        

        if length<4: # nach 4 gesetzten punkten aufhoeren
            if length == 2:
                p1, p2 = points[0], points[1]
                print 'p1, p2'
                print p1, p2
            cv2.circle(image,point,3,(0,0,255),-1,8,0)
            points.append([point])
            print '\n', point
            cv2.imshow("Image Viewer",image)


    if event == cv2.EVENT_RBUTTONDOWN:
        cv2.destroyAllWindows()
        sys.exit(1)
            
if __name__=="__main__":    
    #Bild einer Variable zuweisen
    bild = "fassade.jpg"

    #Bild laden
    global image
    image = cv2.imread(bild, cv2.CV_LOAD_IMAGE_COLOR)
    
    #Fenster erschaffen
    window = cv2.namedWindow("Image Viewer")
    cv2.setMouseCallback("Image Viewer",on_mouse)


    cv2.waitKey(10)
